Skip to content

ref: execution-aligned naming hints for face references (EAPN) - #112

Open
Yulia2233 wants to merge 1 commit into
devfrom
feat/eapn-naming-hints
Open

Yulia2233 wants to merge 1 commit into
devfrom
feat/eapn-naming-hints

Conversation

@Yulia2233

Copy link
Copy Markdown
Contributor

Why

scad.ref names a face by its stable anchor (feature, op, occurrence, role/ordinal | topo) and follows it through the recorded TopoDelta. On notebook models, several classes of faces stay ambiguous or are silently re-targeted after an edit:

class v2.3.0 behaviour
mirror / translate / pattern copies share one birth split on every copied face
several ops made by one line in a loop share a key anchor_ambiguous; after a count change a neighbour can stand in (silent wrong pick)
trace_to_birth stops at a split and names the piece topo=face_N an upstream change silently selects the other piece
ordinals over lists (extrusion.side, fillet.patch) a profile or edge-list change selects another side / patch
callsite_id changes when another line of the cell is edited sibling grouping breaks

Measured on the notebook corpus: with no edit at all, re-resolving every face on the part it was picked from returned that face for 73.7 % of 30,365 faces (385 cases).

What

New simplecadapi.topology.naming_hints. In a code-based model an edit is a new execution of the program, so the hints treat naming as aligning two executions:

  • Execution index of the birth operation and of every copy or repeated operation on the face's history path: stable key, a hash of the call's code text, rank among the call's instances, instance count, own-parameter digest.
  • Alignment on resolve, in this order: a unique, unchanged digest; then the rank, if the instance count is unchanged; then spatial gating within half the old instance spacing; otherwise the operation is removed, which is a modelling fact and is never repaired.
  • Path replay: the existing C++ history walk runs from the aligned birth, and a candidate must pass through exactly the aligned operations. An original never stands for its mirror, and a removed instance never stands for its neighbour.
  • Intra-operation checks:
    • an ordinal is trusted only while the role's entity count is unchanged;
    • a positional anchor also gets a deeper, role-named birth, traced through splits;
    • pieces are told apart by neighbourhood names and axis ranks.
  • A face that history reports as deleted stays lost. Anything not narrowed to one face is split or lost: nothing is chosen silently.

ref.py:

  • ElementRef.hints: plain JSON, excluded from equality, round-trips through to_dict() and repr()/parse().
  • scad.ref.face(..., hints=).
  • scad.ref.of(..., hints=True | "always" | False):
    • True (default) stores hints only for faces that have a known ambiguity class, so plain references such as box.top read exactly as before;
    • "always" also guards against ambiguity that a later edit introduces (e.g. another op of the same kind inserted in the cell). It is the better choice for generated picks (runtime/live_refs.py), which this PR does not change;
    • False is the v2.3.0 behaviour.

Unchanged: the C++ kernel, the anchor format, scad-naming/1, tags, ql, and edge / vertex / solid references. A reference without hints resolves exactly as before.

Results

Edit tasks and ground truth were generated by an LLM agent and validated by script. On pure parameter edits the labels agree 99.8 % with an independent continuation-tracking oracle. Held-out test set (60 cases), correct / silent wrong pick:

normal edits (1,219 targets) hard edits (567 targets)
v2.3.0 scad.ref 80.4 % / 3.3 % 76.9 % / 7.1 %
this PR (of → JSON → from_dict → resolve) 98.6 % / 0.7 % 97.4 % / 1.1 %

No-edit self-consistency goes from 73.7 % to 97.2 % (lost from 11.7 % to 0 %). Making and resolving a reference costs about 111 ms per face, against 21 ms before. Details, ablations and the CadQuery / build123d / graph-matching comparison are in design-docs/persistent-naming-hints.md, added with -f because design-docs/ is in .gitignore.

Tests

  • New test/test_naming_hints.py (6 tests): mirrored copy, removed loop instance, translated copies, reordered instances, split piece after an upstream insert (asserts the v2.3.0 silent wrong pick), hints round trip.
  • test_naming_hints.py, test_ref_api.py and test_element_ref_history.py pass (74 tests). They were run against the v2.3.0 wheel's native module with these Python files overlaid; I have not run the full suite on a dev build.
  • None of the files touched here changed between v2.3.0 and dev.

Not in this PR

  • Switching runtime/live_refs.py to hints="always".
  • Hints for edges and vertices.
  • Moving the history tracing to C++.
  • An editor-level check against the previous B-rep: graph matching was right on all 14 remaining held-out wrong picks.

🤖 Generated with Claude Code

A stable anchor names a face by (feature, op, occurrence, role/ordinal | topo). In notebook models that leaves
several classes ambiguous or silently re-targetable: copies (mirror / translate / pattern) share one birth,
operations made by one line in a loop share a key, split pieces are named by position, ordinals follow lists that
change, and call-site ids change when another line of the cell is edited. Re-resolving every face on the part it
was picked from returned that face for only 73.7 % of 30,365 faces.

Add simplecadapi.topology.naming_hints: at pick time scad.ref.of records JSON hints next to the anchor
(ElementRef.hints): the execution index of the birth operation and of every copy / repeated operation on the
face's history path (stable key, hash of the call's code text, rank among the call's instances, instance count,
own-parameter digest), neighbourhood names, ranks and spacings. On resolve each execution index is aligned to the
new execution (unique unchanged digest > rank when the count is unchanged > spatial gating within half the old
spacing > removed), the C++ history walk runs from the aligned birth, and candidates must pass through exactly the
aligned operations (path replay). Ordinals are trusted only while the role's entity count is unchanged; positional
anchors get a deeper, role-named birth through splits. History that reports a face deleted is final; nothing is
chosen silently.

The anchor format, the naming version and the C++ kernel are unchanged; a reference without hints resolves
exactly as before. of(hints=True) stores hints only for faces with a known ambiguity class, so plain references
read as before; hints="always" also guards against ambiguity a later edit introduces.

Held-out evaluation (60 cases, LLM-generated edits): correct / silent wrong 80.4 / 3.3 % -> 98.6 / 0.7 % on normal
edits, 76.9 / 7.1 % -> 97.4 / 1.1 % on hard edits. See design-docs/persistent-naming-hints.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant